package taskLog

import (
	awesomeTask "awesomeTask/commom"
)

const STATUS_RUNNING = 1 //运行中
const STATUS_FINISH = 2  //结束运行
const TABLE_NAME = "t_task_log"

func CreateLog(taskId string, nodeId string, input string, pid int) int64 {
	data := map[string]interface{}{
		"task_id":  taskId,
		"node_id":  nodeId,
		"input":    input,
		"output":   "",
		"pid":      pid,
		"status":   STATUS_RUNNING,
		"start_at": awesomeTask.Now(),
	}
	return awesomeTask.Insert(TABLE_NAME, data)
}

func UpdateLog(taskLogId int64, stdout string, stderr string, runningTime int64, result string) int64 {
	data := map[string]interface{}{
		"stdout":   stdout,
		"stderr":   stderr,
		"output":   result,
		"end_at":   awesomeTask.Now(),
		"status":   STATUS_RUNNING,
		"start_at": awesomeTask.Now(),
		"run_time": runningTime,
	}
	return awesomeTask.Update(TABLE_NAME, data, "where id=?", taskLogId)
}
